#include "InetAddress.h"

InetAddress::InetAddress(const char *ip, unsigned short port)
    : _ip(ip), _port(port)
{
    _addr.sin_family = AF_INET;
    _addr.sin_addr.s_addr = inet_addr(ip);
    _addr.sin_port = htons(port);
}

InetAddress::InetAddress(const sockaddr_in &addr)
    : _ip(inet_ntoa(addr.sin_addr)), _port(ntohs(addr.sin_port))
{
    _addr.sin_addr = addr.sin_addr;
    _addr.sin_port = addr.sin_port;
    _addr.sin_family = addr.sin_family;
}

unsigned short InetAddress::port() const
{
    return _port;
}

string InetAddress::ip() const
{
    return _ip;
}

sockaddr_in InetAddress::getSockaddr() const
{
    return _addr;
}
